const mysql = require('mysql2/promise');

async function checkDatabaseTables() {
  const connection = await mysql.createConnection({
    host: '43.143.253.188',
    user: 'nextjs',
    password: 'yEAiRE2jcxTyRBy5',
    database: 'nextjs'
  });

  try {
    console.log('🔍 检查数据库表...');
    
    // 获取所有表名
    const [tables] = await connection.execute('SHOW TABLES');
    const tableNames = tables.map(row => Object.values(row)[0]);
    
    console.log(`📊 当前数据库表数量: ${tableNames.length}`);
    console.log('\n📋 所有表名:');
    tableNames.sort().forEach((table, index) => {
      console.log(`${index + 1}. ${table}`);
    });
    
    // 检查娱乐城相关表
    const casinoTables = tableNames.filter(name => name.includes('casino'));
    console.log(`\n🎰 娱乐城相关表 (${casinoTables.length}个):`);
    casinoTables.forEach(table => {
      console.log(`  - ${table}`);
    });
    
    // 检查缺失的娱乐城表
    const expectedCasinoTables = [
      'casino_dice_rounds',
      'casino_dice_bets', 
      'casino_chibi_rounds',
      'casino_chibi_bets',
      'casino_config',
      'casino_operation_log',
      'casino_ranking',
      'casino_rock_paper_scissors'
    ];
    
    const missingCasinoTables = expectedCasinoTables.filter(table => !tableNames.includes(table));
    if (missingCasinoTables.length > 0) {
      console.log(`\n❌ 缺失的娱乐城表 (${missingCasinoTables.length}个):`);
      missingCasinoTables.forEach(table => {
        console.log(`  - ${table}`);
      });
    } else {
      console.log('\n✅ 所有娱乐城表都存在');
    }
    
  } catch (error) {
    console.error('❌ 检查数据库表失败:', error.message);
  } finally {
    await connection.end();
  }
}

checkDatabaseTables();
